
  class Racl::SimpleAcl
    @@enable=false
    def self.enable(&block)
      @@enable=true
      @@ctrl=RACL::Ctrl.new
      block.call @@ctrl
    end
    def self.check_auth_by_controller(group_name,controller)
      check_auth(group_name,controller.request.request_uri,controller.controller_path,controller.action_name)
    end
    def self.check_auth(group_name,uri,controller_name,action_name)
      if @@enable==false
        return true
      end
      if group_name=='__ALL__'
        return true
      elsif group_name=='__PROTECTED__'
        return false
      end
      #white_list first
      white_list_group=@@ctrl.white_list[group_name.to_sym]
      unless white_list_group.nil?
        return true if white_list_group.url_list.include? uri
        actions_list=white_list_group.controller_actions[controller_name.to_sym]
        unless actions_list.nil?
          if actions_list.empty?
            return true
          else
            return true if actions_list.include? action_name
            return true if actions_list.include? action_name.to_sym
          end
        end
      end
      #black_list
      black_list_group=@@ctrl.black_list[group_name.to_sym]
      unless black_list_group.nil?
        return false if black_list_group.url_list.include? uri
        actions_list=black_list_group.controller_actions[controller_name.to_sym]
        unless actions_list.nil?
          if actions_list.empty?
            return false
          else
            return false if actions_list.include? action_name
            return false if actions_list.include? action_name.to_sym
          end
        end
      end
      return true
    end
  end
  class RACL::Ctrl
    attr_accessor :white_list
    attr_accessor :black_list
    def initialize
      @white_list={}
      @black_list={}
    end
    def add_group(groupname,switcher,&block)
      group=RACL::Group.new
      if switcher==:black_list
        @black_list[groupname.to_sym]=group
      else
        @white_list[groupname.to_sym]=group
      end
      block.call group
    end
  end
  class RACL::Group
    attr_accessor :url_list
    attr_accessor :controller_actions
    def initialize
      @url_list=[]
      @controller_actions={}
    end
    def add controlname,action_list=[]
      @controller_actions[controlname.to_sym]=action_list
    end
    def add_url url
      @url_list<< url
    end
  end